
import * as types from '../actions/actionTypes';

const initialState = {
    status: false,
    code: 0,
    message: '',
    user: {},
    share: {},
    isLoading: false,
    isLoggedIn: false,
    haoyouList:[],
    summary:{},
    qianbao:{},
    xianqian:{},
    xianbi:{},
    qianbaoList:[],
    article:{},
    article_id:1110,
    subitems:[],
    subitems2:[],
    haoyouLoading: true,
    registerMsg:'',
    parentName:'',
    formItemList:[],
    formRemarkList: [],
    formTitle:'',
    formButtomName:'',
    formSubmitAction:'',

    log_id :'',
    submit_result :'',
    submit_state :'',
    withdrawList:[],
    chexianRateList:[],

    dom:[],
    lastId:'',
    newestId:'',
    more:'',
};

let userReducer = (state=initialState, action) => {
    switch (action.type) {
        case types.kUserFromSync:
            return {
                ...state,
                ...action,
            };
        case types.kUserRegister:
            return {
                ...state,
                isLoading: true,
            };
        case types.kUserRegisterReceived:
            var isLoggedIn = state.isLoggedIn;
            if (action.status) {
                isLoggedIn = true;
            }
            return {
                ...state,
                ...action,
                isLoading: false,
                isLoggedIn: isLoggedIn,
            };
        case types.kUserLogin:
            return {
                ...state,
                isLoading: true,
            };
        case types.kUserLoginReceived:
            var isLoggedIn = state.isLoggedIn;
            if (action.status) {
                isLoggedIn = true;
            }
            console.log('reducer:',action);
            return {
                ...state,
                ...action,
                isLoading: false,
                isLoggedIn: isLoggedIn,
                user: action.user,
            };
        case types.kUserLogout:
            return {
                ...state,
                isLoading: true,
            };
        case types.kUserLogoutReceived:
            var isLoggedIn = state.isLoggedIn;
            if (action.status) {
                isLoggedIn = false;
            }
            console.log('reducer_action:',action);
            return {
                ...state,
                ...action,
                isLoading: false,
                isLoggedIn: isLoggedIn,
            };
        case types.kUserHaoyouList:
            return {
                ...state,
                haoyouLoading: true,
            };
        case types.kUserHaoyouListReceived:
            return {
                ...state,
                haoyouLoading:false,
                haoyouList: action.haoyouList,
                summary: action.summary,
            };


        case types.kUserQianbao:
            return {
                ...state,
                isLoading: true,
            };
        case types.kUserQianbaoReceived:
            return {
                ...state,
                isLoading:false,
                qianbao: action.qianbao,
            };

        case types.kUserQianbaoList:
            return {
                ...state,
                isLoading: true,
            };
        case types.kUserQianbaoListReceived:
            return {
                ...state,
                isLoading:false,
                qianbaoList: action.qianbaoList,
            };

        case types.kSubItemsByParentId:
            return {
                ...state,
                isLoading: true,
            };
        case types.kSubItemsByParentIdReceived:
            return {
                ...state,
                isLoading:false,
                subitems: action.subitems,
            };
        case types.kSubItemsByParentId2:
            return {
                ...state,
                isLoading: true,
            };
        case types.kSubItemsByParentId2Received:
            return {
                ...state,
                isLoading:false,
                subitems2: action.subitems2,
            };

        case types.kArticleById:
            return {
                ...state,
                isLoading: true,
            };
        case types.kArticleByIdReceived:
            return {
                ...state,
                isLoading:false,
                article: action.article,
            };

        case types.kArticleById2:
            return {
                ...state,
                isLoading: true,
            };
        case types.kArticleById2Received:
            return {
                ...state,
                isLoading:false,
                article: action.article,
            };

        case types.kSelectedDistrict:
            return {
                ...state,
                isLoading:false,
                article_id: action.article_id,
            };



        case types.kSmsVerifyCode:
            return {
                ...state,
                isLoading:false,
            };
        case types.kSmsVerifyCodeReceived:
            return {
                ...state,
                isLoading:false,
                registerMsg:action.registerMsg,
                parentName: action.parentName,
                user:user,
            };
            
        case types.kFormItemList:
            return {
                ...state,
                isLoading:true,
            };
        case types.kFormItemListReceived:
            return {
                ...state,
                isLoading:false,
                formItemList: action.formItemList,
                formTitle:action.formTitle,
                formButtomName:action.formButtomName,
                formSubmitAction:action.formSubmitAction,
                formRemarkList:action.formRemarkList
            }; 

        case types.kSubmitFormItem:
            return {
                ...state,
                isLoading:true,
            };
        case types.kSubmitFormItemListReceived:
            return {
                ...state,
                isLoading:false,
                log_id:action.log_id,
                submit_result:action.submit_result,
                submit_state:action.submit_state,
                withdrawList:action.withdrawList,

            };
        case types.kWithdrawList:
            return {
                ...state,
                isLoading:true,
            };
        case types.kWithdrawListReceived:
            return {
                ...state,
                isLoading:false,
                withdrawList:action.withdrawList,

            };



            
        case types.kListChexianRates:
            return {
                ...state,
                isLoading:true,
            };
        case types.kListChexianRatesReceived:
            return {
                ...state,
                isLoading:false,
                chexianRateList:action.chexianRateList,

            };

        // case types.kSetDomTree:
        //     return {
        //         ...state,
        //         isLoading:true,
                
        //     }; 
        // case types.kSetDomTreeReceived:
        //     return {
        //         ...state,
        //         isLoading:false,
        //         lastId:action.lastId,
        //         newestId:action.newestId,
        //         dom:action.dom
                
        //     };        
        //     case types.kSetDomTreeHeaderReceived:
        //     return {
        //         ...state,
        //         isLoading:false,
        //         lastId:action.lastId,
        //         newestId:action.newestId,
        //         dom:(action.dom.length=0)?action.dom.concat(state.dom):state.dom,
                
        //     };            
        //     case types.kSetDomTreeFooterReceived:
        //     return {
        //         ...state,
        //         isLoading:false,
        //         lastId:action.lastId,
        //         newestId:action.newestId,
        //         dom:(action.dom.length>0)?state.dom.concat(action.dom):state.dom,
        //     };
            
        default:
            return state;
    }
};

export default userReducer;